package com.pj.fantabestconsole.client.mvc;


import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.mvc.View;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.user.client.ui.RootPanel;
import com.pj.fantabestconsole.client.ConsoleEvents;
import com.pj.fantabestconsole.client.ConsoleRegistryKeys;
import com.pj.fantabestconsole.client.widget.NorthContainer;

/**
 * @author giant
 * 
 */
public class ConsoleView extends View {

	private Viewport viewPort;
	private NorthContainer north;
	private LayoutContainer west;
	private LayoutContainer center;

	public ConsoleView(Controller controller) {
		super(controller);
	}

	private void initUI() {
		viewPort = new Viewport();
		viewPort.setLayout(new BorderLayout());

		north = new NorthContainer();
		west = new LayoutContainer(new FitLayout());
		west.setVisible(false);
		center = new LayoutContainer(new FitLayout());
		
		
		Registry.register(ConsoleRegistryKeys.NORTH_CONTAINER, north);
		Registry.register(ConsoleRegistryKeys.WEST_CONTAINER, west);
		Registry.register(ConsoleRegistryKeys.CENTER_PANEL, center);
		Registry.register(ConsoleRegistryKeys.VIEWPORT, viewPort);

		BorderLayoutData northData = new BorderLayoutData(LayoutRegion.NORTH,100);
		northData.setCollapsible(false);
		northData.setFloatable(false);
		northData.setHideCollapseTool(true);
		northData.setSplit(false);
		northData.setMargins(new Margins(0, 0, 0, 0));

		BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 241);
		westData.setSplit(true);
		westData.setCollapsible(true);
		westData.setMaxSize(241);
		westData.setMinSize(0);
		westData.setMargins(new Margins(10,10,10,10));

		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
		centerData.setMargins(new Margins(5, 0, 5, 0));

		viewPort.add(north, northData);
		viewPort.add(west, westData);
		viewPort.add(center, centerData);

		RootPanel.get().add(viewPort);
	}

	@Override
	protected void handleEvent(AppEvent event) {
//		if (event.getType() == ConsoleEvents.Init) {
//			initUI();
//		}	else if(event.getType() == ConsoleEvents.Login)	{
//			BeanModel managerBean = event.getData();
//			if(managerBean!=null)	{
//				Registry.register(ConsoleRegistryKeys.MANAGER_LOGGED_IN, managerBean);
//				LoginWindow loginDialog = Registry.get(ConsoleRegistryKeys.LOGIN_DIALOG);
//				loginDialog.hide();
//				north.getLoginPanel().logManagerIn();
//			}	else	{
//				LoginWindow loginDialog = Registry.get(ConsoleRegistryKeys.LOGIN_DIALOG);
//				loginDialog.setStatusMessage("Sigin failed!");
//			}
//		}	else if(event.getType() == ConsoleEvents.Logoff)	{
//			Registry.unregister(ConsoleRegistryKeys.MANAGER_LOGGED_IN);
//			north.getLoginPanel().logManagerOff();
//		}
	}

}

